home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
GRAPH_FO
/
(GRAPH
/
CGRAPHTE
/
CGRAPHDO.C
< prev
next >
Wrap
Text File
|
1991-02-15
|
9KB
|
255 lines
/******************************************************************************
CGraphDoc.c
The GraphDoc Class
SUPERCLASS = CDocument.c
Copyright ⌐ 1989 Symantec Corporation. All rights reserved.
******************************************************************************/
#include <Global.h>
#include <Commands.h>
#include <CBartender.h>
#include <CDesktop.h>
#include <CDecorator.h>
#include <CScrollPane.h>
#include <CPanorama.h>
#include <CError.h>
#include <TBUtilities.h>
#include "CGraphDoc.h"
#include "CGraphPane.h"
extern CBartender *gBartender; /* Manages all menus */
extern OSType gSignature; /* Creator for Application's files */
extern CDesktop *gDesktop; /* The visible Desktop */
extern CDecorator *gDecorator; /* Decorator for arranging windows */
extern CError *gError; /* global Error handler */
#define WIND_Graph 2000 /* WIND resource ID */
/******************************************************************************
IGraphDoc
Initialize a GraphDoc object
******************************************************************************/
void CGraphDoc::IGraphDoc(
CApplication *itsSupervisor)
{
CDocument::IDocument(itsSupervisor, TRUE);
}
/******************************************************************************
NewFile {OVERRIDE}
Set up a document with a new file, usually in response the "New"
command in the File menu.
******************************************************************************/
void CGraphDoc::NewFile()
{
Str255 wTitle; /* Window title string */
short wCount; /* Index number of new window */
Str63 wNumber; /* Index number as a string */
/* &&& Set up a new document, including an associated window */
BuildWindow(NULL); /* XXX Here we use a BuildWindow() */
/* method with a NULL parameter. */
/* Usually, the OpenFile() method */
/* (see below), will also send a */
/* BuildWindow() message, but */
/* with a handle to some data. */
itsWindow->GetTitle(wTitle); /* Append an index number to the */
wCount = gDecorator->GetWCount(); /* default name of the window */
NumToString((long)wCount, wNumber);
ConcatPStrings(wTitle, (StringPtr) "\p-");
ConcatPStrings(wTitle, wNumber);
itsWindow->SetTitle(wTitle);
itsWindow->Select(); /* Make it the active window */
}
/******************************************************************************
OpenFile {OVERRIDE}
Open a file for a document, usually in response the "Open╔"
command in the File menu.
******************************************************************************/
void CGraphDoc::OpenFile(
SFReply *macSFReply)
{
/* &&& Create and initialize a new file object */
itsFile = new(CFile); /* XXX Create a new file object */
((CFile*)itsFile)->IFile(); /* XXX Initialize file object. Type */
/* casting will be necessary. */
itsFile->Open(fsRdWrPerm); /* Open file with read/write access */
/* &&& Read data from the file and set up the document using */
/* this data. Also create a window for displaying the data. */
BuildWindow(NULL); /* XXX Send BuildWindow() message, */
/* passing parameters which */
/* depend on the data read from */
/* the file. */
/* Set window title to the name of */
/* the file */
itsWindow->SetTitle(macSFReply->fName);
itsWindow->Select(); /* Make this the active window */
}
/******************************************************************************
BuildWindow {XXX}
Build a window for a document. This is NOT an overridden method,
but rather an example of how you might structure your document
class. The NewFile() and OpenFile() methods both require setting
up a new document. NewFile() creates an empty document, possibly
using some default data, whereas OpenFile() creates a document
based on the information read from a file. Both methods can invoke
the BuildWindow(), passing the information needed to set up a
document. BuildWindow() takes care of the common stuff: Creating
a window, and creating and arranging panes within the window.
******************************************************************************/
void CGraphDoc::BuildWindow(
Handle theData) /* XXX Application-specific data */
{
CScrollPane *theScrollPane;
Rect sizeRect;
/* &&& Create a window and the panes which go inside it */
itsWindow = new(CWindow); /* Create a non-floating window */
/* using a WIND resource template */
itsWindow->IWindow(WIND_Graph, FALSE, gDesktop, this);
/* XXX Specify maximum and minimum */
/* dimensions of our window */
gDesktop->GetBounds(&sizeRect);
InsetRect(&sizeRect, 5, 5);
sizeRect.top = sizeRect.left = 100;
itsWindow->SetSizeRect(&sizeRect);
/* Decorator staggers windows on */
/* the screen */
gDecorator->PlaceNewWindow(itsWindow);
/* Create a ScrollPane in the window */
theScrollPane = new(CScrollPane);
/* Use a resource template to set */
/* parameters of the ScrollPane */
theScrollPane->IViewRes('ScPn', 1, itsWindow, this);
/* Make ScrollPane fit snuggly to */
/* the frame of the window */
theScrollPane->FitToEnclFrame(TRUE, TRUE);
/* XXX Put our GraphPane inside */
/* the ScrollPane */
itsMainPane = new(CGraphPane);
((CGraphPane*)itsMainPane)->IViewRes('GrPn', 128, theScrollPane, this);
/* Our Panorama fits inside the */
/* the ScrollPane */
itsMainPane->FitToEnclosure(TRUE, TRUE);
theScrollPane->InstallPanorama((CPanorama*)itsMainPane);
itsGopher = itsMainPane; /* XXX GraphPane may want to be */
/* the Gopher when Document is */
/* active so it can directly */
/* receive key and menu commands */
}
/******************************************************************************
DoSave {OVERRIDE}
Save a file under the same name. Return TRUE if save was successful.
******************************************************************************/
Boolean CGraphDoc::DoSave()
{
gError->PostAlert(131, 1);
}
/******************************************************************************
DoSaveAs {OVERRIDE}
Save a file under another name. Return TRUE if save was successful.
Note that this message is sent by the DoSaveFileAs() method after
the user picks a new name and confirms the save.
******************************************************************************/
Boolean CGraphDoc::DoSaveAs(
SFReply *macSFReply) /* Standard File reply record */
{
if (itsFile != NULL) { /* If a file object already exists, */
itsFile->Dispose(); /* throw it out. This will also */
} /* close the file. */
/* &&& Create and initialize a new file object */
itsFile = new(CFile); /* XXX Create a new file object */
((CFile*)itsFile)->IFile(); /* XXX Initialize file object. Type */
/* casting will be necessary. */
itsFile->SFSpecify(macSFReply); /* Specify file parameters */
/* XXX Create a new file on disk */
/* with desired creator and type. */
/* You'll want to change 'PNTG' */
/* to the file type your program */
/* creates. */
itsFile->CreateNew(gSignature, 'PNTG');
itsFile->Open(fsRdWrPerm); /* Open file with read/write access */
/* Change name of window to match */
/* new file name */
itsWindow->SetTitle(macSFReply->fName);
return( DoSave() ); /* Save contents to disk */
}
/******************************************************************************
DoRevert {OVERRIDE}
Throw out the current contents of a document and revert to the
last saved version.
******************************************************************************/
void CGraphDoc::DoRevert()
{
Point homePos; /* Home position of a Panorama */
/* &&& Dispose of current (in memory) contents of the document */
/* and read the information back from the file on disk. */
/* XXX If you use Panoramas, */
/* remember to reset them back to */
/* the home position */
((CPanorama*)itsMainPane)->GetHomePosition(&homePos);
((CPanorama*)itsMainPane)->ScrollTo(homePos, FALSE);
itsMainPane->Refresh(); /* Force update of contents */
dirty = FALSE; /* Reverts to a clean document */
}